home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
mus
/
edit
/
AlgoRhythms.lha
/
AlgoRhythms
/
Source
/
forms.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-25
|
29KB
|
842 lines
/* forms.c
Copyright (c) 1993 by Thomas E. Janzen
All Rights Reserved
THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
CHANGES FOR FREE DISTRIBUTION. NO TITLE TO AND OWNERSHIP OF THE
SOFTWARE IS HEREBY TRANSFERRED. THOMAS E. JANZEN ASSUMES NO
RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
Thomas E. Janzen
208A Olde Derby Road
Norwood, MA 02062-1761
(617)769-7733
** FACILITY:
**
** AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
** compiled with SAS/C Amiga Compiler 6.50
**
** ABSTRACT:
**
** forms.c supports gadgets (using GadTools) for controlling
** the form of a piece in AlgoRhythms.
**
** AUTHORS: Thomas E. Janzen
**
** CREATION DATE: 23-OCT-1993
**
** MODIFICATION HISTORY:
** DATE NAME DESCRIPTION
** 30 DEC 93 T Janzen new for V3.0
**--
*/
#define INTUI_V36_NAMES_ONLY
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <exec/types.h>
#include <exec/nodes.h>
#include <intuition/intuition.h>
#include <libraries/gadtools.h>
#include <devices/timer.h>
#include <clib/exec_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/utility_protos.h>
#include <clib/dos_protos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include "scale_list.h"
#include "window.h"
#include "forms.h"
#include "algorhythms.h"
#include "scales.h"
#define GAD_PITCH_MEAN_PER (1)
#define GAD_PITCH_MEAN_PHA (2)
#define GAD_PITCH_RANG_PER (3)
#define GAD_PITCH_RANG_PHA (4)
#define GAD_PITCH_RANDOMIZE (5)
#define GAD_PACE_MEAN_PER (6)
#define GAD_PACE_MEAN_PHA (7)
#define GAD_PACE_RANG_PER (8)
#define GAD_PACE_RANG_PHA (9)
#define GAD_PACE_RANDOMIZE (10)
#define GAD_DYN_MEAN_PER (11)
#define GAD_DYN_MEAN_PHA (12)
#define GAD_DYN_RANG_PER (13)
#define GAD_DYN_RANG_PHA (14)
#define GAD_DYN_RANDOMIZE (15)
#define GAD_TEXTURE_RANG_PER (16)
#define GAD_TEXTURE_RANG_PHA (17)
#define GAD_TEXTURE_RANDOMIZE (18)
#define GAD_DURATION (19)
#define GAD_PULSE (20)
#define GAD_MAXVOICES (21)
#define GAD_NOTE_LEN_MIN (22)
#define GAD_NOTE_LEN_MAX (23)
#define GAD_SCALES (24)
#define GAD_TRANSPOSE (25)
#define GAD_LAST (26)
#define C_PITCH_X (50)
#define C_PACE_X (185)
#define C_DYN_X (320)
#define C_TEXTURE_X (455)
#define C_DUR_X (30)
#define C_MAXVOICES_X (150)
#define C_SCALES_X (440)
#define C_TRANSPOSE_X (112)
#define C_PULSE_X (30)
#define C_MIN_X (250)
#define C_MAX_X (250)
#define C_TOP_LINE (25)
#define C_2ND_LINE (52)
#define C_MEAN_PERIOD_Y (80)
#define C_MEAN_PHASE_Y (92)
#define C_RANG_PERIOD_Y (104)
#define C_RANG_PHASE_Y (116)
#define C_RAND_Y (128)
#define C_PHASE_WIDTH (90)
#define C_PERIOD_WIDTH (90)
#define C_RAND_WIDTH (90)
#define SLIDER_MIN ((SHORT)-314)
#define SLIDER_MAX ((SHORT)314)
#define PHASE_FACTOR (100.0)
#define C_PHASE_HEIGHT (12)
#define C_INNER_WINDOW (625)
#define C_COLUMN_WIDTH (C_INNER_WINDOW / 4)
#define C_PERIOD_ADJUST ((C_COLUMN_WIDTH - C_PERIOD_WIDTH) / 2)
#define C_PHASE_ADJUST ((C_COLUMN_WIDTH - C_PHASE_WIDTH) / 2)
#define C_RAND_ADJUST ((C_COLUMN_WIDTH - C_RAND_WIDTH) / 2)
static char
*maxvoices_str[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", NULL};
static struct Node scales_nodes[23]
= {{&scales_nodes[1], NULL, 0, 0, NULL},
{&scales_nodes[2], &scales_nodes[0], 0, 0, SCALE_1_NAME},
{&scales_nodes[3], &scales_nodes[1], 0, 0, SCALE_2_NAME},
{&scales_nodes[4], &scales_nodes[2], 0, 0, SCALE_3_NAME},
{&scales_nodes[5], &scales_nodes[3], 0, 0, SCALE_4_NAME},
{&scales_nodes[6], &scales_nodes[4], 0, 0, SCALE_5_NAME},
{&scales_nodes[7], &scales_nodes[5], 0, 0, SCALE_6_NAME},
{&scales_nodes[8], &scales_nodes[6], 0, 0, SCALE_7_NAME},
{&scales_nodes[9], &scales_nodes[7], 0, 0, SCALE_8_NAME},
{&scales_nodes[10], &scales_nodes[8], 0, 0, SCALE_9_NAME},
{&scales_nodes[11], &scales_nodes[9], 0, 0, SCALE_10_NAME},
{&scales_nodes[12], &scales_nodes[10], 0, 0, SCALE_11_NAME},
{&scales_nodes[13], &scales_nodes[11], 0, 0, SCALE_12_NAME},
{&scales_nodes[14], &scales_nodes[12], 0, 0, SCALE_13_NAME},
{&scales_nodes[15], &scales_nodes[13], 0, 0, SCALE_14_NAME},
{&scales_nodes[16], &scales_nodes[14], 0, 0, SCALE_15_NAME},
{&scales_nodes[17], &scales_nodes[15], 0, 0, SCALE_16_NAME},
{&scales_nodes[18], &scales_nodes[16], 0, 0, SCALE_17_NAME},
{&scales_nodes[19], &scales_nodes[17], 0, 0, SCALE_18_NAME},
{&scales_nodes[20], &scales_nodes[18], 0, 0, SCALE_19_NAME},
{&scales_nodes[21], &scales_nodes[19], 0, 0, SCALE_20_NAME},
{&scales_nodes[22], &scales_nodes[20], 0, 0, SCALE_21_NAME},
{NULL, &scales_nodes[21], 0, 0, NULL}
};
static char pitch_str[] = "PITCH",
pace_str[] = "PACE",
dyn_str[] = "DYNAMIC",
texture_str[] = "TEXTURE",
note_len_str[] = "DURATION";
static struct IntuiText
pitch_txt = {2, 2, INVERSVID | JAM1, 105, 67,
&font_choice, pitch_str, NULL},
pace_txt = {2, 2, INVERSVID | JAM1, 245, 67,
&font_choice, pace_str, &pitch_txt},
dyn_txt = {2, 2, INVERSVID | JAM1, 370, 67,
&font_choice,dyn_str, &pace_txt},
texture_txt = {2, 2, INVERSVID | JAM1, 500, 67,
&font_choice,texture_str, &dyn_txt},
note_len_txt = {2, 2, INVERSVID | JAM1, C_MIN_X + 10,
C_TOP_LINE, &font_choice,note_len_str, &texture_txt};
static struct Window *form_wind = NULL;
static struct Gadget *glist = NULL,
*form_gads[GAD_LAST];
ULONG forms_mask = 0;
static struct Gadget
*create_form_gadgets(void *vi,
UWORD topborder, struct Gadget *form_gads[]);
static SHORT phase_dbl_to_short(const double phase_dbl);
static VOID form_event( struct Gadget *gad, UWORD code,
FORM_TYPE *form, struct timeval *duration,
int *tempo,
NOTE_EVENT_TYPE *events, NOTE_LEN_TYPE *note_len,
int *max_voices, int *scale, int *range,
int *half_range, int *delay_ticks);
static VOID form_event( struct Gadget *gad, UWORD code, FORM_TYPE *form,
struct timeval *duration, int *tempo,
NOTE_EVENT_TYPE *events, NOTE_LEN_TYPE *note_len,
int *max_voices, int *scale, int *range,
int *half_range, int *delay_ticks)
{
switch (gad->GadgetID)
{
case GAD_PITCH_MEAN_PER:
form->frm_s_pitch.prm_d_mean_cycle = (double)
((struct StringInfo *)(gad->SpecialInfo))->LongInt;
break;
case GAD_PITCH_MEAN_PHA:
form->frm_s_pitch.prm_d_mean_phase
= ((double)(SHORT)code) / PHASE_FACTOR;
break;
case GAD_PITCH_RANG_PER:
form->frm_s_pitch.prm_d_range_cycle =
(double)((struct StringInfo *)(gad->SpecialInfo))->LongInt;
break;
case GAD_PITCH_RANG_PHA:
form->frm_s_pitch.prm_d_range_phase
= ((double)(SHORT)code) / PHASE_FACTOR;
break;
case GAD_PITCH_RANDOMIZE:
randomize_parameter(&form->frm_s_pitch);
set_form_gadgets(form, duration, tempo, events,
note_len, *max_voices);
break;
case GAD_PACE_MEAN_PER:
form->frm_s_rhythm.prm_d_mean_cycle =
(double)((struct StringInfo *)(gad->SpecialInfo))->LongInt;
break;
case GAD_PACE_MEAN_PHA:
form->frm_s_rhythm.prm_d_mean_phase
= ((double)(SHORT)code) / PHASE_FACTOR;
break;
case GAD_PACE_RANG_PER:
form->frm_s_rhythm.prm_d_range_cycle =
(double)((struct StringInfo *)(gad->SpecialInfo))->LongInt;
break;
case GAD_PACE_RANG_PHA:
form->frm_s_rhythm.prm_d_range_phase
= ((double)(SHORT)code) / PHASE_FACTOR;
break;
case GAD_PACE_RANDOMIZE:
randomize_parameter(&form->frm_s_rhythm);
set_form_gadgets(form, duration, tempo, events,
note_len, *max_voices);
break;
case GAD_DYN_MEAN_PER:
form->frm_s_dynamic.prm_d_mean_cycle =
(double)((struct StringInfo *)(gad->SpecialInfo))->LongInt;
break;
case GAD_DYN_MEAN_PHA:
form->frm_s_dynamic.prm_d_mean_phase
= ((double)(SHORT)code) / PHASE_FACTOR;
break;
case GAD_DYN_RANG_PER:
form->frm_s_dynamic.prm_d_range_cycle =
(double)((struct StringInfo *)(gad->SpecialInfo))->LongInt;
break;
case GAD_DYN_RANG_PHA:
form->frm_s_dynamic.prm_d_range_phase
= ((double)(SHORT)code) / PHASE_FACTOR;
break;
case GAD_DYN_RANDOMIZE:
randomize_parameter(&form->frm_s_dynamic);
set_form_gadgets(form, duration, tempo, events,
note_len, *max_voices);
break;
case GAD_TEXTURE_RANG_PER:
form->frm_s_texture.prm_d_range_cycle =
(double)((struct StringInfo *)(gad->SpecialInfo))->LongInt;
break;
case GAD_TEXTURE_RANG_PHA:
form->frm_s_texture.prm_d_range_phase
= ((double)(SHORT)code) / PHASE_FACTOR;
break;
case GAD_TEXTURE_RANDOMIZE:
randomize_parameter(&form->frm_s_texture);
set_form_gadgets(form, duration, tempo, events,
note_len, *max_voices);
break;
case GAD_DURATION:
duration->tv_micro = 0L;
duration->tv_secs =
abs(((struct StringInfo *)(gad->SpecialInfo))->LongInt);
break;
case GAD_PULSE:
*tempo =
abs(((struct StringInfo *)(gad->SpecialInfo))->LongInt);
if (*tempo > 0)
{
*delay_ticks = 50 / *tempo;
}
else
{
*delay_ticks = 0;
}
break;
case GAD_MAXVOICES:
*max_voices = code + 1;
break;
case GAD_NOTE_LEN_MIN:
note_len->len_i_min = (int)floor(strtod
(((struct StringInfo *)(gad->SpecialInfo))->Buffer,
(char **)NULL)
* 1000.0);
note_len->len_i_dif
= note_len->len_i_max - note_len->len_i_min;
break;
case GAD_NOTE_LEN_MAX:
note_len->len_i_max = (int)floor(strtod
(((struct StringInfo *)(gad->SpecialInfo))->Buffer,
(char **)NULL)
* 1000.0);
note_len->len_i_dif
= note_len->len_i_max - note_len->len_i_min;
break;
case GAD_SCALES:
*range = install_scale(code + 1, scale);
*half_range = *range / 2;
break;
case GAD_TRANSPOSE:
transpose_scale(
((struct StringInfo *)(gad->SpecialInfo))->LongInt,
scale, *range);
break;
}
return;
}
static struct Gadget *create_form_gadgets(
void *vi, UWORD topborder, struct Gadget *form_gads[])
{
auto struct TagItem /* ti_Tag, ti_Data */
phase_tag_items[] = {{GTSL_Level, 0L},
{GTSL_Min, SLIDER_MIN},
{GTSL_Max, SLIDER_MAX},
{GTSL_LevelFormat, (ULONG)"%4ld"},
{GTSL_MaxLevelLen, 4},
{GTSL_LevelPlace, PLACETEXT_RIGHT},
{TAG_END, 0}},
period_tag_items[] = { {GTIN_Number, 0L}, {TAG_END, 0L}},
rand_tag_items[] = { {TAG_END, 0L}},
note_len_items[] = { {GTST_String, NULL},
{GTST_MaxChars, 10},
{TAG_END, 0L}};
auto struct NewGadget ng;
auto struct Gadget *gad;
gad = CreateContext(&glist);
/*
** Set up Pitch parameters
*/
/*
** First set up Pitch Mean Period
*/
ng.ng_LeftEdge = C_PITCH_X + C_PERIOD_ADJUST;
ng.ng_TopEdge = C_MEAN_PERIOD_Y;
ng.ng_Width = C_PERIOD_WIDTH;
ng.ng_Height = 12;
ng.ng_GadgetText = "MEAN Per";
ng.ng_TextAttr = &font_choice;
ng.ng_VisualInfo = vi;
ng.ng_GadgetID = GAD_PITCH_MEAN_PER;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_LEFT;
form_gads[GAD_PITCH_MEAN_PER]
= gad = CreateGadgetA(INTEGER_KIND, gad, &ng, period_tag_items);
/*
** Set up Pitch Mean Phase
*/
ng.ng_LeftEdge = C_PITCH_X + C_PHASE_ADJUST;
ng.ng_TopEdge = C_MEAN_PHASE_Y;
ng.ng_Width = C_PHASE_WIDTH;
ng.ng_Height = C_PHASE_HEIGHT;
ng.ng_GadgetText = "Phase";
ng.ng_GadgetID = GAD_PITCH_MEAN_PHA;
form_gads[GAD_PITCH_MEAN_PHA] = gad =
CreateGadgetA(SLIDER_KIND, gad, &ng, phase_tag_items);
/*
** Set up Pitch Range Period
*/
ng.ng_LeftEdge = C_PITCH_X + C_PERIOD_ADJUST;
ng.ng_TopEdge = C_RANG_PERIOD_Y;
ng.ng_Width = C_PERIOD_WIDTH;
ng.ng_Height = 12;
ng.ng_GadgetText = "RANGE Per";
ng.ng_GadgetID = GAD_PITCH_RANG_PER;
form_gads[GAD_PITCH_RANG_PER]
= gad = CreateGadgetA(INTEGER_KIND, gad, &ng, period_tag_items);
/*
** Set up Pitch Range Phase
*/
ng.ng_LeftEdge = C_PITCH_X + C_PHASE_ADJUST;
ng.ng_TopEdge = C_RANG_PHASE_Y;
ng.ng_Width = C_PHASE_WIDTH;
ng.ng_Height = C_PHASE_HEIGHT;
ng.ng_GadgetText = "Phase";
ng.ng_GadgetID = GAD_PITCH_RANG_PHA;
form_gads[GAD_PITCH_RANG_PHA] = gad =
CreateGadgetA(SLIDER_KIND, gad, &ng, phase_tag_items);
/*
** Set up Pitch Randomize
*/
ng.ng_LeftEdge = C_PITCH_X + C_RAND_ADJUST;
ng.ng_TopEdge = C_RAND_Y;
ng.ng_Width = C_RAND_WIDTH;
ng.ng_Height = 12;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_IN;
ng.ng_GadgetText = "Randomize";
ng.ng_GadgetID = GAD_PITCH_RANDOMIZE;
form_gads[GAD_PITCH_RANDOMIZE]
= gad = CreateGadgetA(BUTTON_KIND, gad, &ng, rand_tag_items);
/*
** Set up Pace
*/
/*
** Set up Pace Mean Period
*/
ng.ng_LeftEdge = C_PACE_X + C_PERIOD_ADJUST;
ng.ng_TopEdge = C_MEAN_PERIOD_Y;
ng.ng_Width = C_PERIOD_WIDTH;
ng.ng_Height = 12;
ng.ng_Flags = 0;
ng.ng_GadgetText = NULL;
ng.ng_GadgetID = GAD_PACE_MEAN_PER;
form_gads[GAD_PACE_MEAN_PER] = gad
= CreateGadgetA(INTEGER_KIND, gad, &ng, period_tag_items);
/*
** Set up Pace Mean Phase
*/
ng.ng_LeftEdge = C_PACE_X + C_PHASE_ADJUST;
ng.ng_TopEdge = C_MEAN_PHASE_Y;
ng.ng_Width = C_PHASE_WIDTH;
ng.ng_Height = C_PHASE_HEIGHT;
ng.ng_GadgetText = NULL;
ng.ng_GadgetID = GAD_PACE_MEAN_PHA;
form_gads[GAD_PACE_MEAN_PHA] = gad =
CreateGadgetA(SLIDER_KIND, gad, &ng, phase_tag_items);
/*
** Set up Pace Range Period
*/
ng.ng_LeftEdge = C_PACE_X + C_PERIOD_ADJUST;
ng.ng_TopEdge = C_RANG_PERIOD_Y;
ng.ng_Width = C_PERIOD_WIDTH;
ng.ng_Height = 12;
ng.ng_GadgetText = NULL;
ng.ng_GadgetID = GAD_PACE_RANG_PER;
form_gads[GAD_PACE_RANG_PER] = gad
= CreateGadgetA(INTEGER_KIND, gad, &ng, period_tag_items);
/*
** Set up Pace Range Phase
*/
ng.ng_LeftEdge = C_PACE_X + C_PHASE_ADJUST;
ng.ng_TopEdge = C_RANG_PHASE_Y;
ng.ng_Width = C_PHASE_WIDTH;
ng.ng_Height = C_PHASE_HEIGHT;
ng.ng_GadgetText = NULL;
ng.ng_GadgetID = GAD_PACE_RANG_PHA;
form_gads[GAD_PACE_RANG_PHA] = gad =
CreateGadgetA(SLIDER_KIND, gad, &ng, phase_tag_items);
/*
** Set up Pace Randomize
*/
ng.ng_LeftEdge = C_PACE_X + C_RAND_ADJUST;
ng.ng_TopEdge = C_RAND_Y;
ng.ng_Width = C_RAND_WIDTH;
ng.ng_Height = 12;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_IN;
ng.ng_GadgetText = "Randomize";
ng.ng_GadgetID = GAD_PACE_RANDOMIZE;
form_gads[GAD_PACE_RANDOMIZE] = gad
= CreateGadgetA(BUTTON_KIND, gad, &ng, rand_tag_items);
/*
** Set up Dynamics
*/
/*
** Set up Dynamic Mean Period
*/
ng.ng_LeftEdge = C_DYN_X + C_PERIOD_ADJUST;
ng.ng_TopEdge = C_MEAN_PERIOD_Y;
ng.ng_Width = C_PERIOD_WIDTH;
ng.ng_Height = 12;
ng.ng_GadgetText = NULL;
ng.ng_Flags = 0L;
ng.ng_GadgetID = GAD_DYN_MEAN_PER;
form_gads[GAD_DYN_MEAN_PER] = gad
= CreateGadgetA(INTEGER_KIND, gad, &ng, period_tag_items);
/*
** Set up Dynamic Mean Phase
*/
ng.ng_LeftEdge = C_DYN_X + C_PHASE_ADJUST;
ng.ng_TopEdge = C_MEAN_PHASE_Y;
ng.ng_Width = C_PHASE_WIDTH;
ng.ng_Height = C_PHASE_HEIGHT;
ng.ng_GadgetText = NULL;
ng.ng_GadgetID = GAD_DYN_MEAN_PHA;
form_gads[GAD_DYN_MEAN_PHA] = gad =
CreateGadgetA(SLIDER_KIND, gad, &ng, phase_tag_items);
/*
** Set up Dynamic Range Period
*/
ng.ng_LeftEdge = C_DYN_X + C_PERIOD_ADJUST;
ng.ng_TopEdge = C_RANG_PERIOD_Y;
ng.ng_Width = C_PERIOD_WIDTH;
ng.ng_Height = 12;
ng.ng_GadgetText = NULL;
ng.ng_GadgetID = GAD_DYN_RANG_PER;
form_gads[GAD_DYN_RANG_PER] = gad
= CreateGadgetA(INTEGER_KIND, gad, &ng, period_tag_items);
/*
** Set up Dynamic Range Phase
*/
ng.ng_LeftEdge = C_DYN_X + C_PHASE_ADJUST;
ng.ng_TopEdge = C_RANG_PHASE_Y;
ng.ng_Width = C_PHASE_WIDTH;
ng.ng_Height = C_PHASE_HEIGHT;
ng.ng_GadgetText = NULL;
ng.ng_GadgetID = GAD_DYN_RANG_PHA;
form_gads[GAD_DYN_RANG_PHA] = gad =
CreateGadgetA(SLIDER_KIND, gad, &ng, phase_tag_items);
/*
** Set up Dynamic Randomize
*/
ng.ng_LeftEdge = C_DYN_X + C_RAND_ADJUST;
ng.ng_TopEdge = C_RAND_Y;
ng.ng_Width = C_RAND_WIDTH;
ng.ng_Height = 12;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_IN;
ng.ng_GadgetText = "Randomize";
ng.ng_GadgetID = GAD_DYN_RANDOMIZE;
form_gads[GAD_DYN_RANDOMIZE] = gad
= CreateGadgetA(BUTTON_KIND, gad, &ng, rand_tag_items);
/*
** Set up Texture
*/
/*
** Set up Texture Range Period
*/
ng.ng_LeftEdge = C_TEXTURE_X + C_PERIOD_ADJUST;
ng.ng_TopEdge = C_RANG_PERIOD_Y;
ng.ng_Width = C_PERIOD_WIDTH;
ng.ng_Height = 12;
ng.ng_GadgetText = NULL;
ng.ng_Flags = NULL;
ng.ng_GadgetID = GAD_TEXTURE_RANG_PER;
form_gads[GAD_TEXTURE_RANG_PER]
= gad = CreateGadgetA(INTEGER_KIND, gad, &ng, period_tag_items);
/*
** Set up Texture Range Phase
*/
ng.ng_LeftEdge = C_TEXTURE_X + C_PHASE_ADJUST;
ng.ng_TopEdge = C_RANG_PHASE_Y;
ng.ng_Width = C_PHASE_WIDTH;
ng.ng_Height = C_PHASE_HEIGHT;
ng.ng_GadgetText = NULL;
ng.ng_GadgetID = GAD_TEXTURE_RANG_PHA;
form_gads[GAD_TEXTURE_RANG_PHA] = gad =
CreateGadgetA(SLIDER_KIND, gad, &ng, phase_tag_items);
/*
** Set up Texture Randomize
*/
ng.ng_LeftEdge = C_TEXTURE_X + C_RAND_ADJUST;
ng.ng_TopEdge = C_RAND_Y;
ng.ng_Width = C_RAND_WIDTH;
ng.ng_Height = 12;
ng.ng_GadgetText = "Randomize";
ng.ng_GadgetID = GAD_TEXTURE_RANDOMIZE;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_IN;
form_gads[GAD_TEXTURE_RANDOMIZE]
= gad = CreateGadgetA(BUTTON_KIND, gad, &ng, rand_tag_items);
/*
** Set up Duration
*/
ng.ng_LeftEdge = C_DUR_X;
ng.ng_TopEdge = C_TOP_LINE;
ng.ng_Width = 80;
ng.ng_Height = 12;
ng.ng_GadgetText = "Duration";
ng.ng_GadgetID = GAD_DURATION;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_ABOVE;
form_gads[GAD_DURATION] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
TAG_END);
/*
** Set up Max Voices
*/
ng.ng_LeftEdge = C_MAXVOICES_X;
ng.ng_TopEdge = C_TOP_LINE;
ng.ng_Width = 50;
ng.ng_Height = 12;
ng.ng_GadgetText = "MaxVoices";
ng.ng_GadgetID = GAD_MAXVOICES;
form_gads[GAD_MAXVOICES]
= gad
= CreateGadget(CYCLE_KIND, gad, &ng, GTCY_Labels, maxvoices_str,
TAG_END);
/*
** Set up Scales list
*/
ng.ng_LeftEdge = C_SCALES_X;
ng.ng_TopEdge = C_TOP_LINE - 10;
ng.ng_Width = 180;
ng.ng_Height = 48;
ng.ng_GadgetText = "Scale";
ng.ng_GadgetID = GAD_SCALES;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_LEFT;
form_gads[GAD_SCALES] = gad = CreateGadget(LISTVIEW_KIND, gad, &ng,
GTLV_Labels, scales_nodes, GTLV_ShowSelected, NULL, TAG_END);
/*
** Set up Pulse
*/
ng.ng_LeftEdge = C_PULSE_X;
ng.ng_TopEdge = C_2ND_LINE;
ng.ng_Width = 40;
ng.ng_Height = 12;
ng.ng_GadgetText = "Pulse";
ng.ng_GadgetID = GAD_PULSE;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_ABOVE;
form_gads[GAD_PULSE] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
TAG_END);
/*
** Set up minimum note length
*/
ng.ng_LeftEdge = C_MIN_X;
ng.ng_TopEdge = C_2ND_LINE - 12;
ng.ng_Width = 80;
ng.ng_Height = 12;
ng.ng_GadgetText = "Min";
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_LEFT;
ng.ng_GadgetID = GAD_NOTE_LEN_MIN;
form_gads[GAD_NOTE_LEN_MIN] = gad
= CreateGadgetA(STRING_KIND, gad, &ng, note_len_items);
/*
** Set up maximum note length
*/
ng.ng_LeftEdge = C_MAX_X;
ng.ng_TopEdge = C_2ND_LINE;
ng.ng_Width = 80;
ng.ng_Height = 12;
ng.ng_GadgetText = "Max";
ng.ng_GadgetID = GAD_NOTE_LEN_MAX;
form_gads[GAD_NOTE_LEN_MAX] = gad
= CreateGadgetA(STRING_KIND, gad, &ng, note_len_items);
/*
** Set up Transposition
*/
ng.ng_LeftEdge = C_TRANSPOSE_X;
ng.ng_TopEdge = C_2ND_LINE;
ng.ng_Width = 60;
ng.ng_Height = 12;
ng.ng_GadgetText = "Transpose";
ng.ng_GadgetID = GAD_TRANSPOSE;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_ABOVE;
form_gads[GAD_TRANSPOSE] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
GTST_String, "0", GTST_MaxChars, 3,
TAG_END);
return gad;
}
int process_form_events(FORM_TYPE *form, struct timeval *duration,
int *tempo,
NOTE_EVENT_TYPE *events, NOTE_LEN_TYPE *note_len,
int *max_voices, int *scale, int *range,
int *half_range, int *delay_ticks)
{
auto int result = 0;
auto int Closing = FALSE;
auto ULONG imsgClass;
auto UWORD imsgCode;
auto struct Gadget *gad;
auto struct IntuiMessage *imsg;
while (imsg = GT_GetIMsg(form_wind->UserPort))
{
gad = (struct Gadget *)imsg->IAddress;
imsgClass = imsg->Class;
imsgCode = imsg->Code;
GT_ReplyIMsg(imsg);
switch(imsgClass)
{
case IDCMP_CLOSEWINDOW:
Closing = TRUE;
break;
case IDCMP_GADGETDOWN:
case IDCMP_MOUSEMOVE:
case IDCMP_GADGETUP:
form_event(gad, imsgCode, form, duration, tempo,
events, note_len, max_voices, scale, range,
half_range, delay_ticks);
result = 1;
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(form_wind);
SetAPen(rast_port, 2);
PrintIText(form_wind->RPort, ¬e_len_txt, 1, 1);
GT_EndRefresh(form_wind, TRUE);
break;
}
}
if (Closing)
{
close_forms();
}
return result;
}
VOID open_forms_window(VOID)
{
auto UWORD topborder;
if (form_wind != NULL)
{
return;
}
topborder = main_screen->WBorTop
+ (main_screen->Font->ta_YSize + 1);
if (NULL == create_form_gadgets(vi, topborder,
form_gads))
{
;
}
else
{
if (NULL == (form_wind = OpenWindowTags(NULL,
WA_Top, 59,
WA_Title, "FORM PARAMETERS",
WA_Gadgets, glist, WA_AutoAdjust, TRUE,
WA_Width, 640, WA_MinWidth, 640,
WA_InnerHeight, 130, WA_MinHeight, 140,
WA_DragBar, TRUE, WA_DepthGadget, TRUE,
WA_Activate, TRUE,
#if 0
WA_CloseGadget, TRUE,
#endif
WA_SimpleRefresh, TRUE,
WA_IDCMP, IDCMP_REFRESHWINDOW /* | IDCMP_CLOSEWINDOW */
| SLIDERIDCMP | LISTVIEWIDCMP
| STRINGIDCMP | BUTTONIDCMP | CYCLEIDCMP,
WA_CustomScreen, main_screen, TAG_DONE, 0UL)))
{
;
}
else
{
RefreshGList(glist, form_wind, NULL, -1);
GT_RefreshWindow(form_wind, NULL);
SetAPen(rast_port, 2);
PrintIText(form_wind->RPort, ¬e_len_txt, 1, 1);
forms_mask = 1 << form_wind->UserPort->mp_SigBit;
}
}
return;
}
void close_forms(void)
{
RemoveGList(form_wind, glist, -1);
CloseWindowSafely(form_wind);
form_wind = NULL;
FreeGadgets(glist);
glist = NULL;
return;
}
void set_form_gadgets(FORM_TYPE *form, struct timeval *duration,
int *tempo,
NOTE_EVENT_TYPE *events, NOTE_LEN_TYPE *note_len,
int max_voices)
{
auto char temp_str[24];
auto int gad_index;
GT_SetGadgetAttrs(form_gads[GAD_PITCH_MEAN_PER], form_wind,
NULL, GTIN_Number, (int)floor(form->frm_s_pitch.prm_d_mean_cycle),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_PITCH_MEAN_PHA], form_wind,
NULL, GTSL_Level,
phase_dbl_to_short(form->frm_s_pitch.prm_d_mean_phase),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_PITCH_RANG_PER], form_wind,
NULL, GTIN_Number, (int)floor(form->frm_s_pitch.prm_d_range_cycle),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_PITCH_RANG_PHA], form_wind,
NULL, GTSL_Level,
phase_dbl_to_short(form->frm_s_pitch.prm_d_range_phase),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_PACE_MEAN_PER], form_wind,
NULL, GTIN_Number, (int)floor(form->frm_s_rhythm.prm_d_mean_cycle),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_PACE_MEAN_PHA], form_wind,
NULL, GTSL_Level,
phase_dbl_to_short(form->frm_s_rhythm.prm_d_mean_phase),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_PACE_RANG_PER], form_wind,
NULL, GTIN_Number, (int)floor(form->frm_s_rhythm.prm_d_range_cycle),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_PACE_RANG_PHA], form_wind,
NULL, GTSL_Level,
phase_dbl_to_short(form->frm_s_rhythm.prm_d_range_phase),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_DYN_MEAN_PER], form_wind,
NULL, GTIN_Number, (int)floor(form->frm_s_dynamic.prm_d_mean_cycle),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_DYN_MEAN_PHA], form_wind,
NULL, GTSL_Level,
phase_dbl_to_short(form->frm_s_dynamic.prm_d_mean_phase),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_DYN_RANG_PER], form_wind,
NULL, GTIN_Number, (int)floor(form->frm_s_dynamic.prm_d_range_cycle),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_DYN_RANG_PHA], form_wind,
NULL, GTSL_Level,
phase_dbl_to_short(form->frm_s_dynamic.prm_d_range_phase),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_TEXTURE_RANG_PER], form_wind,
NULL, GTIN_Number, (int)floor(form->frm_s_texture.prm_d_range_cycle),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_TEXTURE_RANG_PHA], form_wind,
NULL, GTSL_Level,
phase_dbl_to_short(form->frm_s_texture.prm_d_range_phase),
TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_PULSE], form_wind,
NULL, GTIN_Number, *tempo, TAG_END, 0L);
sprintf(temp_str, "%5.2f", note_len->len_i_min / 1000.0);
GT_SetGadgetAttrs(form_gads[GAD_NOTE_LEN_MIN], form_wind,
NULL, GTST_String, temp_str, TAG_END, 0L);
sprintf(temp_str, "%5.2f", note_len->len_i_max / 1000.0);
GT_SetGadgetAttrs(form_gads[GAD_NOTE_LEN_MAX], form_wind,
NULL, GTST_String, temp_str, TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_DURATION], form_wind,
NULL, GTIN_Number, duration->tv_secs, TAG_END, 0L);
GT_SetGadgetAttrs(form_gads[GAD_MAXVOICES], form_wind,
NULL, GTCY_Active, max_voices - 1, TAG_END, 0L);
return;
}
static SHORT phase_dbl_to_short(const double phase_dbl)
{
auto SHORT tmp_short;
tmp_short = (SHORT)(floor(fabs(phase_dbl * PHASE_FACTOR) + 0.5));
if (phase_dbl < 0.0)
{
tmp_short = -tmp_short;
}
return tmp_short;
}